<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>单向数据流</h2>
      <child :name="name" :age="age"></child>
    </div>

    <script src="../Vue.js"></script>
    <script>
      // props的值是不能被改变的
      const Child = {
        props: {
          name: String,
          age: Number,
        },
        // 组件不能去改变props的值
        // 将props的值作为组件的data的初始值
        // data() {
        //   return {
        //     age2: this.age,
        //   };
        // },
        computed: {
          age2() {
            return this.age * 2;
          },
        },
        template: `
          <div>child组件 - {{ name }} - {{ age2 }}</div>
        `,
        // mounted() {
        //   setTimeout(() => {
        //     this.age2 = 30;
        //   }, 2000);
        // },
      };
      new Vue({
        el: "#app",
        data: {
          name: "pengshao",
          age: 20,
        },
        components: {
          Child,
        },
        // mounted() {
        //   setTimeout(() => {
        //     this.age = 30;
        //   }, 2000);
        // },
      });
    </script>
  </body>
</html>
